//
//  TopicInformationView.m
//  ECBBusinessCamp
//
//  Created by rimi on 16/6/20.
//  Copyright © 2016年 邓毕华. All rights reserved.
//

#import "TopicInformationView.h"

@implementation TopicInformationView

#pragma mark 🌷🌷🌷life cycle🌷🌷🌷
- (instancetype)init
{
    self = [super init];
    if (self) {
        // 添加视图
        [self addSubview:self.leftImageView];
        [self addSubview:self.themeLabel];
        [self addSubview:self.originatorLabel];
        [self addSubview:self.deadlineLabel];
        [self addSubview:self.numberPeopleLabel];
        [self addSubview:self.joinButton];
        [self addSubview:self.overdueImageView];
        
        // 自动布局
        [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.sizeOffset(CGSizeMake(SCREEN_WIDTH * 0.26, SCREEN_WIDTH * 0.18));
            make.centerY.equalTo(self);
            make.left.offset(SCREEN_WIDTH * 0.02);
        }];
        [_themeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(SCREEN_WIDTH * 0.3);
            make.top.offset(SCREEN_WIDTH * 0.1);
        }];
        [_originatorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_themeLabel);
            make.top.equalTo(_themeLabel.mas_bottom).offset(SCREEN_WIDTH * 0.01);
        }];
        [_deadlineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_themeLabel);
            make.top.equalTo(_originatorLabel.mas_bottom).offset(SCREEN_WIDTH * 0.01);
        }];
        [_numberPeopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(SCREEN_WIDTH * -0.036);
            make.top.equalTo(_themeLabel);
        }];
        [_joinButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.sizeOffset(CGSizeMake(SCREEN_WIDTH * 0.1, SCREEN_WIDTH * 0.035));
            make.left.equalTo(_numberPeopleLabel);
            make.top.offset(SCREEN_WIDTH * 0.15);
        }];
        [_overdueImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.offset(SCREEN_WIDTH * 0.15);
            make.height.equalTo(_overdueImageView.mas_width).multipliedBy(0.48);
            make.center.equalTo(_joinButton);
        }];
    }
    return self;
}

#pragma mark 🌷🌷🌷event response🌷🌷🌷
- (void)respondsToJoinBtn:(UIButton *)sender {
    NSMutableDictionary * parameters = [NSMutableDictionary dictionary];
    [parameters setObject:_eid forKey:@"eid"];
    
    [[NetTool sharedTool] requestMethod:POST loadingMsg:@"正在提交参与请求..." url:BASEURLAPPEND(STUDENTSENJOYABLEJOIN_URL) parameters:parameters finish:^(id responseObject, NSError *error) {
        if (!error) {
            NSString * status = (NSString *)responseObject[@"status"];
            NSString * message = @"参与成功";
            switch ([status integerValue]) {
                case 0:
                    message = @"参与失败";
                    break;
                case 2:
                    message = @"已参与过分享";
                    break;
                case 3:
                    message = @"用户不存在";
                    break;
                case 4:
                    message = @"尊享不存在";
                    break;
                case 5:
                    message = @"发起人不能参与";
                    break;
                    
                default:
                    break;
            }
            [MBProgressHUD showSuccess:message];
        }
    }];
}

#pragma mark 🌷🌷🌷getters and setters🌷🌷🌷
- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc] init];
        _leftImageView.backgroundColor = [UIColor redColor];
    }
    return _leftImageView;
}
- (UILabel *)themeLabel {
    if (!_themeLabel) {
        _themeLabel = [[UILabel alloc] init];
        _themeLabel.textColor = RGB_COLOR(145, 145, 145, 1);
        _themeLabel.font = [UIFont systemFontOfSize:25];
        _themeLabel.text = @"尊享主题：1";
    }
    return _themeLabel;
}
- (UILabel *)originatorLabel {
    if (!_originatorLabel) {
        _originatorLabel = [[UILabel alloc] init];
        _originatorLabel.textColor = RGB_COLOR(145, 145, 145, 1);
        _originatorLabel.font = [UIFont systemFontOfSize:25];
        _originatorLabel.text = @"尊享主题：1";
    }
    return _originatorLabel;
}
- (UILabel *)deadlineLabel {
    if (!_deadlineLabel) {
        _deadlineLabel = [[UILabel alloc] init];
        _deadlineLabel.textColor = RGB_COLOR(145, 145, 145, 1);
        _deadlineLabel.font = [UIFont systemFontOfSize:25];
        _deadlineLabel.text = @"尊享主题：1";
    }
    return _deadlineLabel;
}
- (UILabel *)numberPeopleLabel {
    if (!_numberPeopleLabel) {
        _numberPeopleLabel = [[UILabel alloc] init];
        _numberPeopleLabel.textColor = RGB_COLOR(145, 145, 145, 1);
        _numberPeopleLabel.font = [UIFont systemFontOfSize:25];
        _numberPeopleLabel.text = @"尊享主题：1";
    }
    return _numberPeopleLabel;
}
- (UIButton *)joinButton {
    if (!_joinButton) {
        _joinButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_joinButton setTitle:@"参与尊享" forState:UIControlStateNormal];
        [_joinButton setTitleColor:RGB_COLOR(145, 145, 145, 1) forState:UIControlStateNormal];
        _joinButton.titleLabel.font = [UIFont systemFontOfSize:25];
        _joinButton.layer.borderColor = RGB_COLOR(194, 194, 194, 1).CGColor;
        _joinButton.layer.borderWidth = 1;
        _joinButton.layer.cornerRadius = 12;
        _joinButton.layer.masksToBounds = true;
        [_joinButton addTarget:self action:@selector(respondsToJoinBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _joinButton;
}
- (UIImageView *)overdueImageView {
    if (!_overdueImageView) {
        _overdueImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"已过期.png"]];
    }
    return _overdueImageView;
}

@end
